package com.cn.lyl.servlet.nav;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.NavModel;
import com.cn.lyl.service.NavService;
import com.cn.lyl.service.impl.NavServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/nav/add")
public class AddNavServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String title = req.getParameter("title");
        String href = (req.getParameter("href"));

        NavModel navModel = new NavModel();
        navModel.setTitle(title);
        navModel.setHref(href);
        NavService newsService =new NavServiceImpl();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",newsService.addNav(navModel));
        resp.getWriter().print(jsonObject);
    }
}
